package impl

import (
	"context"
	"github.com/starmotioncf/soutchatinternal/model"
	"github.com/starmotioncf/soutchatinternal/repository"
)

type orderRepository struct {
	*repository.Repository
}

func NewOrderRepository(r *repository.Repository) repository.OrderRepository {
	return &orderRepository{
		Repository: r,
	}
}

// Get 获取一个订单
func (r *orderRepository) Get(ctx context.Context, orderNo string) (m *model.Order, err error) {
	err = r.DB(ctx).Where("order_no = ?", orderNo).First(&m).Error
	return
}

// PreCreate 预创建订单
func (r *orderRepository) PreCreate(ctx context.Context, order *model.Order) error {
	return r.DB(ctx).Create(order).Error
}
